package cn.plushine.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.HashMap;

/**
 * 调用高德的API获取省市区数据
 */
@Component
// 通过@ConfigurationProperties注解给属性赋值
@ConfigurationProperties(prefix = "gaode")
public class GaoDeUtils {
    // api接口地址
    private static String url;
    // 调用api所需要的key
    private static String key;

    // 获取省市区（县）级地名
    public static String district(String keywords) {
        // bug-fixed：调用接口返回的内容包含转义符
        return HttpRequestUtils.sendGetAndRetrieveContent(url + "?key=" + key + "&keywords=" + keywords + "&subdistrict=1");
    }

    // get、set方法
    public static String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        GaoDeUtils.url = url;
    }

    public static String getKey() {
        return key;
    }

    public void setKey(String key) {
        GaoDeUtils.key = key;
    }
}
